define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_list(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": ' +
					'{"doing": [{"act_id": "act_id_001","name": "新年促销","goods_count": 10,"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_002","name": "新年促销","goods_count": 10,"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}],' +
					'"pending": [{"act_id": "act_id_003","name": "新客户促销","goods_count": 10,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_004","name": "新客户促销","goods_count": 10,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}],' +
					'"ended": [{"act_id": "act_id_005","name": "圣诞促销","goods_count": 10,"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},{"act_id": "act_id_006","name": "圣诞促销","goods_count": 10,"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_promotions_list(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"act": [' +
					'{"act_id": "act_id_001","act_name": "新年促销","store_id": "001","store_name": "上海五金店","introduction": "新年促销大让利","goods_count": 10,' +
					'"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}},' +
					'{"act_id": "act_id_002","act_name": "新年促销","store_id": "002","store_name": "北京五金店","introduction": "新年促销大让利","goods_count": 10,' +
					'"member_count": 100,"start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","image": {"id": "001","image": "./img/upload/pro-img01.jpg"}}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		//返回信息
		return {
			promotions_list: function(nPage,act_type,from_type,callback,calldone) {
				Http.post({
					method: 'marketing.promotion.viewlist',
					act_type: act_type,
					pagelimit: 20,
					nPage: nPage,
					from_type:from_type
				}, function(result) {
					if(callback)
						callback(get_data_promotions_list(result).result,result.process_time);
				}, function(e) {

				}, function() {
					if(calldone)
					calldone();
				})
			},
			get_loginfo:function(callback){
				Http.post({
					method:'chat.group.getlogininfo'
				},function(result){
					if(callback)
					callback(result.result);
				})
			},
			//轮播图   8：产品推广  9：产品促销
			getBannerList: function(act_type,callback) {
				Http.post({
					method: 'marketing.banner.getlist',
					act_type:act_type
				}, function(result) {
					if(callback) {
						callback(result);
					}
				}, function(e) {
					//请求异常
				}, function() {
					
				});
			}
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Promotions", factory);
});